package Arrays;
//                              Arrages.copyOf()
import java.util.Arrays;
public class Test2 {


//模拟实现Arrages.copyOf()
    public static int[] copyOf(int[] arr, int newlength){
        int[] result = new int[newlength];
        int len = Math.min(newlength, arr.length);
        int i = 0;
        for (i = 0; i < len; i++){
            result[i] = arr[i];
        }
        return result;
    }

    //数组拷贝
    public static void main(String[] args) {
        int[] arr1 = {1, 2, 3, 4, 5};
        //1.Arrages.copyOf()
        int[] arr2 = Arrays.copyOf(arr1,5);
        System.out.println(Arrays.toString(arr2));
        //2.Arrages.copyOfRange
        int[] arr3 = Arrays.copyOfRange(arr1,1,3);//前闭后开区间     range----区间
        System.out.println(Arrays.toString(arr3));
        //
        int[] arr4 = copyOf(arr1, 7);
        System.out.println(Arrays.toString(arr4));

    }
}
